﻿using System;
using System.Collections.Generic;
using System.Linq;
using Common.Model;
using Common.util;
using Newtonsoft.Json;

namespace Common.Redis
{
    public class HqRedisProvider
    {
        private static string HqRedisKey = "hq:l1:snapshot";
        private static string HqPublishKey = "hq:l1:publish";
        
        public static QuoteRt GetHq(string key)
        {
            string quoteJson = null;
            if (RedisUtils.HtRedis.GetDatabase().HashExists(HqRedisKey, key))
                quoteJson = RedisUtils.HtRedis.GetDatabase().HashGet(HqRedisKey, key);

            if (null == quoteJson)
                return null;

            return JsonConvert.DeserializeObject<QuoteRt>(quoteJson);
        }

        public static List<QuoteRt> GetHq()
        {
            var hEntry = RedisUtils.HtRedis.GetDatabase().HashGetAll(HqRedisKey);
            return hEntry.Select(m=> JsonConvert.DeserializeObject<QuoteRt>(m.Value)).ToList();
        }
    }
}